#pragma once

#include <osg/Referenced>
#include <osg/NodeCallback>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/ref_ptr>
#include <osg/Array>
#include <QString>

namespace osgText
{
	class Text;
}

namespace osg
{
	class Node;
	class Billboard;
	class Drawable;
	class PositionAttitudeTransform;
	class Geometry;
	class Group;
}

namespace VrDataCore
{
	class MarkNodeWithBillboard:public osg::Referenced
	{
	public:
		MarkNodeWithBillboard();

		enum WithNodeType
		{
			NONE,
			DIAMOND,
		};
		osg::ref_ptr<osg::Billboard> createBillboardNode(bool withtext);
		void setBillboardMode(const QString& mode);
		QString getBillboardMode();
		void setAxis(const osg::Vec3& vecaxis);
		osg::Vec3 getAxis();
		void setNormal(const osg::Vec3& vecnormal);
		osg::Vec3 getNormal();
		void update();
		void setBillboardSize(int z);
		void setBillboardColor(const osg::Vec4& color);
		void addOsgText(const std::string& text);
		void setText(const std::string& text);
		void setTextSetting(const osg::Vec3& relativepos,const osg::Vec4& color);
		osg::ref_ptr<osg::Node> createWithNode(WithNodeType withnode,const osg::Vec3& colorval,osg::Group* parent = NULL);
		void startAnimation(float upspeed,float rotatespeed);
		void endAnimation();
		void setBillboardNodePosition(const osg::Vec3& position);
		void setBillboardTextPosition(const osg::Vec3& position);
		void setBillboardPolygonPosition(const osg::Vec3& position);
	protected:
		bool										_withText;
		osg::ref_ptr<osg::Billboard>				_billboard;
		QString										_billboardMode;
		WithNodeType								_withNodeType;
		std::string									_showText;
		bool										_updateSize;
		bool										_updateColor;
		bool										_updateAnimation;
		bool										_isUp;
		float										_size_z;
		float										_upSpeed;
		float										_rotateSpeed;
		osg::Vec4									_color;
		osg::Vec3									_withNodeColor;
		osg::Vec3									_geometryDefaultPosition;
		osg::ref_ptr<osgText::Text>					_text;
		osg::Vec3									_textDefaultPosition;
		osg::ref_ptr<osg::PositionAttitudeTransform>	_billboardModelNode;
		osg::Vec3										_billboardModelNodeDefaultPosition;
		osg::ref_ptr<osg::Billboard>					_billboardNode;
		virtual ~MarkNodeWithBillboard();
		osg::Group* createPyramid( float width ,float height,const osg::Vec3& color, float alpha=0.5, bool isglow = true);
	};

	class BillboardUpdateCallback : public osg::NodeCallback
	{
	public:
		BillboardUpdateCallback(MarkNodeWithBillboard* ba)
		{
			_ba = ba ;
		}
		~BillboardUpdateCallback(){} ;
		virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)
		{
			if( !_ba )
				return ;
			_ba->update() ;
		}
	protected:
		MarkNodeWithBillboard *_ba ;
	};
}